<?php

namespace App\Models\System;

use App\Models\BaseModel;
use App\Models\Kms\User\KmsUser;
use App\Models\Traits\KfSoftDeletes;
use App\Models\Traits\KfUid;
use DateTimeInterface;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;

class SystemNotifyCenterModel extends BaseModel
{
    use KfSoftDeletes, KfUid;

    protected $table = 'system_notify_center';


    protected $fillable = [
        'title',
        'type',
        'target',
        'targetId',
        'isSystem',
        'smsTemplate',
        'pushTitle',
        'url',
        'method',
        'summary',
        'content',
        'autoRules',
        'isPopup',
        'presenceArea',
        'status',
        'isOffPop',
        'popEffectiveDay',
        'popEffectiveTime',
        'region',
        'pushType',
        'pushLocationUrl',
        'pushTargetId'
    ];

    protected $appends = [
    ];


    const PUSH_TYPE_1        = 1;
    const PUSH_TYPE_2        = 2;
    const PUSH_TYPE_3        = 3;
    const PUSH_TYPE_TEXT     = [
        self::PUSH_TYPE_1 => "文章",
        self::PUSH_TYPE_2 => "链接",
        self::PUSH_TYPE_3 => "图文",
    ];
    const WEB_PUSH_TYPE_TEXT = [
        self::PUSH_TYPE_1 => "文章",
        self::PUSH_TYPE_2 => "链接",
    ];

    const NOTIFY_TYPE_DIRECT = 1;
    const NOTIFY_TYPE_DELAY  = 2;
    const NOTIFY_TYPE_TEXT   = [
        self::NOTIFY_TYPE_DIRECT => "立即推送",
        self::NOTIFY_TYPE_DELAY  => "延时推送",
    ];

    protected function serializeDate(DateTimeInterface $date)
    {
        return $date->format("Y-m-d H:i:s");
    }

    public function notifyUserOneRel(): HasOne
    {
        return $this->hasOne(SystemNotifyUserModel::class, 'notifyCenterId', 'id');
    }

    //公告分类
    const NOTIFY_TYPE_1 = 1;
    const NOTIFY_TYPE_2 = 2;
    const NOTIFY_TYPE_3 = 3;
    const NOTIFY_TYPE_4 = 4;
    const NOTIFY_TYPE_5 = 5;

    const NOTIFY_TYPE_6 = 6; // 群聊

    const NOTIFY_TYPE_MAPPING_WEB_SHOW = [
        self::NOTIFY_TYPE_1 => '订货消息',
        self::NOTIFY_TYPE_2 => '服务消息',
        self::NOTIFY_TYPE_3 => '待办消息',
        self::NOTIFY_TYPE_4 => '开店进度',
    ];

    const NOTIFY_TYPE_MAPPING = [
        self::NOTIFY_TYPE_1 => '订货消息',
        self::NOTIFY_TYPE_2 => '服务消息',
        self::NOTIFY_TYPE_3 => '待办消息',
        self::NOTIFY_TYPE_4 => '开店进度',
        self::NOTIFY_TYPE_5 => '门店消息'
    ];

    const NOTIFY_TYPE_ICON_MAPPING = [
        self::NOTIFY_TYPE_1 => 'https://file.51kuafu.com/5c/fc/3c182d5a5553c11c5184dea057f5fdd105b265d63d0644930c1a54cba7d3.png',
        self::NOTIFY_TYPE_2 => 'https://file.51kuafu.com/b5/58/fdbcb6ce742b485f02da1a61ebd8046f5966014d7c345b24342618741a20.png',
        self::NOTIFY_TYPE_3 => 'https://file.51kuafu.com/04/40/a57fac0d14e15676b9f8253a44725ee650b73728230251c4a9ed68d96f52.png',
        self::NOTIFY_TYPE_4 => 'https://file.51kuafu.com/84/88/99d599ede2be4414b5afc8dcd362dbff578a6812a44dd033d4503417a28f.png',
        self::NOTIFY_TYPE_5 => 'https://file.51kuafu.com/70/95/75a0a88ca6d5183a3e3084cad970767348cb96a0556c769d98bee038de5e.png',
        self::NOTIFY_TYPE_6 => 'https://file.51kuafu.com/a6/2a/c543ea6af8262bf0b527e25be29a6c2aab7d1ba394eea1526de45e3805db.png',
    ];

    //公告状态
    const NOTIFY_STATUS_1 = 1;
    const NOTIFY_STATUS_2 = 2;
    const NOTIFY_STATUS_3 = 3;
    const NOTIFY_STATUS_4 = 4;

    const NOTIFY_STATUS_MAPPING = [
        self::NOTIFY_STATUS_1 => '未推送',
        self::NOTIFY_STATUS_2 => '推送中',
        self::NOTIFY_STATUS_3 => '推送成功',
        self::NOTIFY_STATUS_4 => '已关闭',
    ];

    // 通知对象
    const NOTIFY_TARGET_1 = 1;
    const NOTIFY_TARGET_2 = 2;
    const NOTIFY_TARGET_3 = 3;

    const NOTIFY_TARGET_MAPPING = [
        self::NOTIFY_TARGET_1 => '店长',
        self::NOTIFY_TARGET_2 => '所有人(店长+店员)',
        self::NOTIFY_TARGET_3 => '个人账号',
    ];

    /**
     * 前段展示字段
     */
    const NOTIFY_TARGET_MAPPING_WEB = [
        self::NOTIFY_TARGET_1 => '店长',
        self::NOTIFY_TARGET_2 => '所有人(店长+店员)',
    ];

    // 通知位置
    const NOTICE_PRESENCE_AREA_1 = 1;
    const NOTICE_PRESENCE_AREA_2 = 2;
    const NOTICE_PRESENCE_AREA_3 = 3;
    const NOTICE_PRESENCE_AREA_4 = 4;


    const NOTIFY_PRESENCE_AREA_MAPPING = [
        self::NOTICE_PRESENCE_AREA_1 => '首页',
        self::NOTICE_PRESENCE_AREA_2 => '订货',
//        self::NOTICE_PRESENCE_AREA_3 => '我的',
        self::NOTICE_PRESENCE_AREA_4 => '门店',
    ];

    // 是否系统生成
    const NOTIFY_IS_SYSTEM_NO  = 0;
    const NOTIFY_IS_SYSTEM_YES = 1;

    const IS_POPUP_ON  = 1;  //是否弹窗  是
    const IS_POPUP_OFF = 0;  // 否


    const METHOD_TYPE_NOT_SET   = 0;   //未设置
    const METHOD_TYPE_MANUAL    = 1;   //手动
    const METHOD_TYPE_AUTOMATIC = 2;   //自动

    const METHOD_TYPES = [
        self::METHOD_TYPE_NOT_SET   => '未设置',
        self::METHOD_TYPE_MANUAL    => '手动',
        self::METHOD_TYPE_AUTOMATIC => '自动',
    ];


    /**
     * @return HasOne
     */
    public function updatedUserRel(): HasOne
    {
        return $this->hasOne(KmsUser::class, "rmsUserId", "updatedByUid");
    }
}
